package com.green.voluntaryfiling.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.green.voluntaryfiling.common.DataGridView;
import com.green.voluntaryfiling.common.ResultObj;
import com.green.voluntaryfiling.domain.UniversityScoreByMajor;
import com.green.voluntaryfiling.service.UniversityScoreByMajorService;
import com.green.voluntaryfiling.mapper.UniversityScoreByMajorMapper;
import com.green.voluntaryfiling.vo.MajorDetailRes;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 *
 */
@Service
public class UniversityScoreByMajorServiceImpl extends ServiceImpl<UniversityScoreByMajorMapper, UniversityScoreByMajor>
    implements UniversityScoreByMajorService{

    @Autowired
    private UniversityScoreByMajorMapper universityScoreByMajorMapper;

    @Autowired
    RedisTemplate redisTemplate;//redis缓存

    //存放redis用户查询的key
    private  static LinkedList<String> queryMajorWithNameKeys = new LinkedList<>();


    @Override
    public int getRankingByScore(String kobetu, int score){
        //MySQL查询优化  (所有合理区间的分数均能返回对应排位）
        Integer majorLowestRanking = universityScoreByMajorMapper.selectMajorLowestRankingByKobetsuAndMajorLowestScore(kobetu, score);

        return majorLowestRanking;
    }

    /**
     * 查询学校的专业ALL
     * @param university_name
     * @param subject
     * @return
     */
    @Override
    public DataGridView queryMajorWithName(String university_name, String subject) {
        List<MajorDetailRes> list = this.universityScoreByMajorMapper.selectMajorWithName(university_name,subject);
        if (list == null){
            return null;
        }else {
            return new DataGridView(Long.valueOf(list.size()),list);
        }
    }
}




